home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / dice-3.16.lha / doc / romable.doc < prev    next >
Text File  |  1994-02-13  |  16KB  |  438 lines

  1.  
  2. romable/romable                           romable/romable
  3.  
  4.                   ROMABLE.DOC
  5.  
  6.                GENERATING ROMABLE FIRMWARE
  7.  
  8.                   REFERENCES
  9.  
  10.     Please refer to the following DCC options:
  11.  
  12.     -pi    generate position independant code.  All code references
  13.         forced to PC-relative
  14.  
  15.     -pr    generate residentable position independant code.  Unless
  16.         -mw is specified A4 relative addressing is used for data
  17.         items.    All code references forced  to PC-relative.
  18.  
  19.     -ma    specify that initialized data + bss will be hardwired to
  20.         a known address
  21.  
  22.     -mw    specify that initialized data + bss will be hardwired to
  23.         a known address and all of data + bss occurs somewhere
  24.         within the first 32KBytes of the address space
  25.         (0x0000-0x7FFF).  Also allows DICE to use A4 as a register
  26.         variable.
  27.  
  28.     -ms    const items go into EPROM in local cases
  29.  
  30.     -mS    const items go into EPROM in local and external cases
  31.  
  32.     The following documentation may appear confusing, but only because so
  33.     many possibilities exist when one intends to put code in ROM.  When you
  34.     are in doubt, it is usually a good idea to write a small test source
  35.     file, compile it, link it with symbols, and then look at the resulting
  36.     executable with DOBJ.
  37.  
  38.  
  39.               MAKING ROMABLE PROGRAMS
  40.  
  41.     DICE has the capability to generate ROMABLE programs.  That is, program
  42.     binaries that you can use to directly burn an EPROM.  When generating
  43.     ROMABLE code you have more data model options available to you.  The
  44.     basic idea of ROMd code is as follows:
  45.                ________________
  46. FIXED ADDRESS = EPROM |            |
  47.               | 68000 vectors  |    const data objects
  48.               |----------------|
  49.               |     CODE       |
  50.               |----------------|
  51.               |  const DATA    |    string constants and other
  52.               |            |    const items, stays in eprom.
  53.               |----------------|
  54.               | read-only copy |
  55.               | of initialized |    this is copied to a working
  56.               | data           |    RAM copy by the reset code
  57.               |________________|
  58.  
  59.                ________________
  60. FIXED ADDRESS = RAM   | run-time copy  |    (copied from EPROM by startup)
  61.               | of initialized |
  62.               | data           |
  63.               |----------------|    (cleared by EPROM startup)
  64.               | run-time BSS   |
  65.               |________________|
  66.  
  67.  
  68.     From the above you have two basic choices in terms of where your
  69.     RUN-TIME DATA is based.  If your RAM exists in low-memory
  70.     (0x0000-0x7FFF) you may choose to compile your code to use the
  71.     ABSOLUTE-WORD addressing mode.  This modes takes the same space as the
  72.     A4-RELATIVE addressing mode yet does not require use of the A4 register
  73.     and, in fact, the A4 register will then be available for use as a
  74.     register variable.
  75.  
  76.     If you have minimal RAM in low-memory or your DATA+BSS is larger than
  77.     32KBytes (yes, that's 32KBytes people, not 64KBytes), then you will
  78.     have to choose either the formal large-data model or the A4-relative
  79.     small data model.  If you initialized data is over 64KBytes you can
  80.     still use the small-data model for most objects by using the __far
  81.     keyword judiciously.
  82.  
  83.     NOTE: in all cases you can allocate or generate points for any ram
  84.     location, this just refers to accesses of declared variables!  Pointers
  85.     are always 32 bits.
  86.  
  87.     model        options     advantages          disadvantages
  88.  
  89.     absolute-word    -mw    -ms    no need for A4          low 32KBytes only
  90.                     A4 available as
  91.                     reg variable
  92.  
  93.     small-data        -ma    -ms    RAM can be anywhere   requires A4
  94.                                   must use __geta4
  95.  
  96.     large-data        -ma -mD -ms    RAM can be anywhere   code is larger
  97.                                   libs must all be
  98.                                   large-data
  99.  
  100.  
  101.                 CODE MODEL
  102.  
  103.     The CODE MODEL is normally left at PC-relative and should not present a
  104.     problem.
  105.  
  106.                 CONST DATA
  107.  
  108.     You want to use the -ms option or even the -mS option (see DCC.DOC for
  109.     the differences).  This will place all string constants in EPROM and
  110.     IN THE CODE SEGMENT, thus this initialized data will NOT take up space
  111.     in RAM.  Any 'const' initialized data will be placed in the code segment
  112.     and thus in EPROM.    Any non-const initialized data will be copied from
  113.     EPROM into RAM by your reset-startup code.
  114.  
  115.     Any tables that you declare that you will never modify should be
  116.     declared const so they reside in EPROM and do not take up space in RAM.
  117.     On the otherhand, if your EPROM is running 6 wait states and your RAM
  118.     is running 0 you might consider not using 'const'.... assuming you have
  119.     a lot of RAM.
  120.  
  121.     When your code is less than 32KBytes big you can use -pi or -pr and
  122.     should definitely use -mS.    When your code is larger than 32KBytes you
  123.     cannot use -mS unless you are absolutely positive pc-relative const
  124.     data references do not exceed the word-relative range.
  125.  
  126.               RESET VECTOR, DATA MODEL SETUP
  127.  
  128.     If your EPROM is mapped into low memory on boot you can declare a vector
  129.     table by declaring a CONST LONG array as the first data object in the
  130.     first object module that you link to create the executable:
  131.  
  132.     const long ROMVectorTable[] = {
  133.         InitialSSP,
  134.         ResetVector,
  135.           .
  136.           .
  137.           .
  138.     };
  139.  
  140.     Remember, this must be the first data declaration in the first object
  141.     module!!!  If you are using the A4-RELATIVE small-data model you must
  142.     qualify your ResetVector with the __geta4 type qualifier to set up A4.
  143.  
  144.     In most cases you will want ResetVector to point to some assembly which
  145.     initializes your RAM DATA & BSS before calling C code.  The assembly
  146.     normally looks like this (this would be the second object in the link):
  147.  
  148.         ;   RESET exception, copy initialized data to RAM and clear
  149.         ;   BSS area before calling rom_main()
  150.         ;
  151.         ;   Assumes less than 256KBytes of data and 256KBytes of BSS
  152.  
  153.         xref    __DATA_BAS        ; linker generated symbols
  154.         xref    __ABSOLUTE_BAS
  155.         xref    __DATA_LEN
  156.         xref    __BSS_LEN
  157.         xref    _rom_main
  158.  
  159. _ResetVector
  160.         lea    __DATA_BAS,A0        ; ROM data
  161.         lea    __ABSOLUTE_BAS,A1   ; RAM data
  162.         move.w    #__DATA_LEN,D0        ; long words of data
  163.         bra    trentry
  164. trloop        move.l    (A0)+,(A1)+         ; copy EPROM copy to run-time
  165. trentry     dbf    D0,trloop        ; RAM copy.
  166.  
  167.         move.w    #__BSS_LEN,D0        ; long words of BSS (follows data)
  168.         moveq.l #0,D1
  169.         bra    trbentry
  170. trbloop     move.l    D1,(A1)+            ; clear run-time RAM
  171. trbentry    dbf    D0,trbloop
  172.  
  173.         jmp    _rom_main(pc)
  174.  
  175.     Where rom_main() is your C main routine qualified with __geta4 (if you
  176.     are using the A4-RELATIVE data model).  Any special items, such as
  177.     the EPROM getting mapped at reset, must be dealt with as well, usually
  178.     before the reset code sets up the run-time enviroment.
  179.  
  180.     If you are using the ABSOLUTE-WORD data model DO NOT USE __GETA4!
  181.     Specifically, the -mw option TELLS DICE THAT A4 IS FREE FOR USE AS A
  182.     NORMAL REGISTER VARIABLE.  This gives you an extra register variable if
  183.     you haven't guessed!
  184.  
  185.                    EXAMPLE PROGRAM
  186.  
  187.     Assume the above assembly module has been assembled and is called
  188.     'romc.o'.  The following C program is called 'test.c'.  In all cases
  189.     the code may start anywhere.
  190.  
  191.     Also, in all cases note that ROMC.O is specified AFTER test in the
  192.     DCC line (that also serves as the link line).  This is because for
  193.     a standalone product we want our CONST data object that is the
  194.     ROM VECTOR TABLE to be first.  Of course, if you put the ROM VECTOR
  195.     TABLE in ROMC.A instead of TEST.C then ROMC.A would go first.  To
  196.     put the ROM VECTOR TABLE in ROMC.A it should be the first data
  197.     object declarations (dc.l's) in the CODE segment.
  198.  
  199.  
  200.     (1) SMALL-DATA-MODEL
  201.  
  202.     extern void TrapReset();
  203.     extern char SSp[512];
  204.  
  205.     const long RomVectors[] = { (long)SSp, (long)TrapReset };
  206.  
  207.     char SSp[512];        /*    our supervisor stack in BSS */
  208.  
  209.     __geta4 void
  210.     rom_main()
  211.     {
  212.         short i;
  213.  
  214.         for (;;) {
  215.         for (i = 0; i < 10000; ++i) {
  216.             <do something here with  i>
  217.         }
  218.         }
  219.     }
  220.                     note, ram can be beyond 64K
  221.                     v
  222.  
  223.     COMPILE:    dcc test.c romc.o -ma 0x10000 -o t:test -r -v -lrom
  224.             romable t:test -o t:test.bin -D 0x10000 -C 0x0
  225.             burn eprom using test.bin
  226.  
  227.  
  228.     (2) ABSOLUTE WORD DATA MODEL
  229.  
  230.     The source code is the same except you do not need __geta4.  Here
  231.     I am assuming RAM starts at, say, 0x2000.
  232.  
  233.     void
  234.     rom_main()
  235.     {
  236.         ...
  237.     }